<?php
/**
 * Triple-B micro Framework for PHP5
 * Copyright (C) 2013  PT. Triple-B Shamany
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @resource
 * @singleton
 */
final class Index {
    /**
     * Jika pengguna belum login, customize bisa dilakukan apakah akan
     * menampilkan content untuk komsumsi publik atau pada kasus sistem
     * informasi, menampilkan halaman login.
     *
     * @gzip
     */
    public function GET($module = "vfs") {
        $ufwk = getService();
        $meta = meta()->API;
        $outp = getService($meta->Output);
        $mobi = getService($meta->Sniffer)->mobile();
        $tmpl = "vfs/META-INF/T.%s.html";
        if ($ufwk->isUser()) {
            $conn = getConnection("ufwk");
            $rset = $conn->executeQuery("SELECT * FROM vfs_packages WHERE PKG_CODE='%s' AND BEGDA<=CURRENT_DATE AND BEGDA IS NOT NULL AND (ENDDA>=CURRENT_DATE OR ENDDA IS NULL)", $module);
            if ($rset->next()) {
                $outp->load(sprintf($tmpl, $mobi ? "GUI.mobile" : "GUI"),
                    array(
                        "module" => $module, "conf" => meta()->Config
                    )
                );
            } else {
                quit(meta()->moduleNotFound($module));
            }
        } else {
            $STR = getService($meta->String);
            $UID = $STR->random();
            $PID = $STR->random();
            $_SESSION["MD5"] = md5($STR->random().time());
            $_SESSION["UID"] = $UID;
            $_SESSION["PID"] = $PID;
            $outp->load(sprintf($tmpl, $mobi ? "SIGNIN.mobile" : "SIGNIN"),
                array(
                    "module" => $module, "conf" => meta()->Config,
                    "USR" => $STR->random(), "PWD" => $STR->random(), "UID" => $UID, "PID" => $PID, "MD5" => $_SESSION["MD5"],
                    "HND" => $STR->random(), "BND" => $STR->random()
                )
            );
        }
    }
}
?>